package com.pda.smallbug.myapplication;

import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.pda.smallbug.myapplication.httpDomain.LoginHttp;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/6/27.
 */

public class LoginAdapter extends RecyclerView.Adapter{
    private final LoginActivity context;
    private List<LoginHttp.LoginData> data=new ArrayList<>();

    public LoginAdapter(LoginActivity context){
        this.context=context;
    }
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
       View view= context.getLayoutInflater().inflate(R.layout.simple_spinner_item,parent,false);
        MyViewHolder holder=new MyViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder1, final int position) {
        MyViewHolder holder= (MyViewHolder) holder1;
        ((TextView)holder.itemView).setText(data.get(position).getFusername());
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                context.select(position);
            }
        });
    }

    @Override
    public int getItemCount() {
        return data.size();
    }

    public void update(List<LoginHttp.LoginData> data) {
        this.data=data;
        notifyDataSetChanged();
    }

    private class MyViewHolder extends RecyclerView.ViewHolder{

        public MyViewHolder(View itemView) {
            super(itemView);
        }
    }
}
